package com.atguigu.springcloud.controller;


import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController

public class PaymentController {
    Logger logger = LoggerFactory.getLogger(PaymentController.class);
    @Resource
    private PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult create( Payment payment) {
        int result = paymentService.create(payment);
        logger.info("*******************************************插入结果:" + result);
        if (result > 0) {
            return new CommonResult(200,"插入数据成功!",result);
        }else {
            return new CommonResult(444,"插入数据失败!", null);
        }
    }

    @GetMapping("/payment/findPayment/{id}")
    public CommonResult<Payment> findPayment(@PathVariable("id") long id) {
        Payment payment = paymentService.getPaymentById(id);
        logger.info("*******************************************插入结果:" + payment);
        if (payment != null) {
            return new CommonResult(200,"成功查询到数据!", payment);
        }else {
            return new CommonResult(444,"未查询到数据!", null);
        }
    }
}
